/*
 * cpuid.c
 *
 *  Created on: Aug 27, 2010
 *      Author: artur
 */

#include <platformjack.h>

static struct cpu_id cpu;

struct cpu_id *
get_cpuid(void)
{
	return &cpu;
}

void
update_cpuid(void)
{
	unsigned int register eax;
	unsigned int register edx;
	unsigned int register ebx;
	unsigned int register ecx;

	/* invoke 'cpuid' */
	__asm__ volatile (
			"cpuid"
			: "=b" (ebx), "=c" (ecx), "=d" (edx)
			: "a" ((long)(0))
			);

	*(unsigned int *)cpu.vendor = ebx;
	*(((unsigned int *)cpu.vendor) + 1) = edx;
	*(((unsigned int *)cpu.vendor) + 2) = ecx;
	cpu.vendor[12] = 0;

	/* invoke 'cpuid' */
	__asm__ volatile (
			"cpuid"
			: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
			: "a" ((long)(1))
			);

	cpu.features_raw = eax;
	cpu.tlb_info = ebx;
	cpu.serial = ecx;
	cpu.ext_features = edx;

	return;
}

